package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CBanner;
import com.ruoyi.camp.service.ICBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/camp/banner")
public class CBannerController extends BaseController
{
    @Autowired
    private ICBannerService cBannerService;

    /**
     * 查询广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(CBanner cBanner)
    {
        startPage();
        List<CBanner> list = cBannerService.selectCBannerList(cBanner);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:export')")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CBanner cBanner)
    {
        List<CBanner> list = cBannerService.selectCBannerList(cBanner);
        ExcelUtil<CBanner> util = new ExcelUtil<CBanner>(CBanner.class);
        util.exportExcel(response, list, "广告管理数据");
    }

    /**
     * 获取广告管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(cBannerService.selectCBannerByBannerId(bannerId));
    }

    /**
     * 新增广告管理
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CBanner cBanner)
    {
        return toAjax(cBannerService.insertCBanner(cBanner));
    }

    /**
     * 修改广告管理
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CBanner cBanner)
    {
        return toAjax(cBannerService.updateCBanner(cBanner));
    }

    /**
     * 删除广告管理
     */
    @PreAuthorize("@ss.hasPermi('camp:banner:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(cBannerService.deleteCBannerByBannerIds(bannerIds));
    }
}
